home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 60750 / 60750.xpi / chrome / chromeFiles / content / bindings / btboommenubutton.xml < prev    next >
Extensible Markup Language  |  2010-01-20  |  4KB  |  122 lines

  1. <?xml version="1.0"?>
  2.  
  3. <bindings id="btbuttonBindings"
  4.       xmlns="http://www.mozilla.org/xbl"
  5.       xmlns:html="http://www.w3.org/1999/xhtml"
  6.       xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  7.       xmlns:xbl="http://www.mozilla.org/xbl">
  8.  
  9.   <binding id="btboommenubutton" extends="xul:box">
  10.     <content>
  11.       <xul:hbox>
  12.         <xul:button type="menu"
  13.                     xbl:inherits="label">
  14.           <xul:menupopup anonid="btboommenubutton-popup">
  15.             <children/>
  16.           </xul:menupopup> 
  17.         </xul:button>
  18.         </xul:hbox>
  19.     </content>
  20.     <handlers>
  21.       <handler event="command">
  22.         <![CDATA[
  23.           var subject = {};
  24.           subject.wrappedJSObject = this.brandObject;
  25.           this.observerService.notifyObservers(subject, "brandthunder", event.originalTarget.id);
  26.           if (event.originalTarget.hasAttribute("boom")) {
  27.             this.btPrefBranch.setCharPref("currentBoom", event.originalTarget.getAttribute("boom"));
  28.           }
  29.         ]]>
  30.       </handler>
  31.       <handler event="popupshowing">
  32.         <![CDATA[
  33.         switch (event.originalTarget.getAttribute("anonid")) {
  34.           case "btboommenubutton-popup":
  35.             var currentBoom = this.btPrefBranch.getCharPref("currentBoom");
  36.             for (let i= event.originalTarget.childNodes.length - 1; i >= 0; i--) {
  37.               var menuitem = event.originalTarget.childNodes.item(i);
  38.               if (menuitem.getAttribute("boom") == currentBoom) {
  39.                 menuitem.setAttribute("checked", "true");
  40.               } else {
  41.                 menuitem.setAttribute("checked", "false");
  42.               }
  43.             }
  44.             break;
  45.         }
  46.         ]]>
  47.       </handler>
  48.     </handlers>
  49.     <implementation>
  50.       <constructor>
  51.         <![CDATA[
  52.         this.observerService = Components.classes["@mozilla.org/observer-service;1"]
  53.                                          .getService(Components.interfaces.nsIObserverService)
  54.         if (this.hasAttribute('btBoomBundle')) {
  55.           this.btBoomBundle = document.getElementById(this.getAttribute('btBoomBundle'));
  56.         }
  57.         if (this.hasAttribute('btClientBundle')) {
  58.           this.btClientBundle = document.getElementById(this.getAttribute('btClientBundle'));
  59.         }
  60.         if (this.hasAttribute('brand')) {
  61.           this.brandObject = BrandThunder.clients[this.getAttribute('brand')];
  62.         }
  63.         
  64.         if (this.brandObject) {
  65.           this.btPrefBranch = Components.classes["@mozilla.org/preferences-service;1"]
  66.                                         .getService(Components.interfaces.nsIPrefService)
  67.                                         .getBranch("extensions.brandthunder.");
  68.         }
  69.         if ((this.btBoomBundle) || (this.btClientBundle)) {
  70.           var label = this.getString(this.id + ".label");
  71.           if (label) {
  72.             this.setAttribute("label", label);
  73.           }
  74.           var menupopup = getAnonymousElementByAttribute(this, "anonid", "btboommenubutton-popup");
  75.           if (menupopup.childNodes.length == 0) {
  76.             var i = 1;
  77.             var menuitem;
  78.             for (var boom in this.brandObject.booms) {
  79.               menuitem = document.createElement("menuitem");
  80.               menuitem.setAttribute("label", brandObject.booms[boom]);
  81.               menuitem.setAttribute("id", this.id + "-" + i);
  82.               menuitem.setAttribute("boom", boom);
  83.               menuitem.setAttribute("type", "checkbox");
  84.               menupopup.appendChild(menuitem);
  85.               i++;
  86.             }
  87.           }
  88.         }
  89.         ]]>
  90.       </constructor>
  91.       <destructor>
  92.       </destructor>
  93.       <field name="btPrefBranch"/>
  94.       <field name="brandObject"/>
  95.       <field name="btBoomBundle"/>
  96.       <field name="btClientBundle"/>
  97.       <field name="observerService"/>
  98.       <method name="getString">
  99.         <parameter name="id"/>
  100.         <body>
  101.           <![CDATA[
  102.           var string;
  103.           if (this.btBoomBundle) {
  104.             try {
  105.               string = this.btBoomBundle.getString(id);
  106.             } catch(ex) {
  107.             }
  108.           }
  109.           if (!string) {
  110.             try {
  111.               string = this.btClientBundle.getString(id);
  112.             } catch(ex) {
  113.             }
  114.           }
  115.           return string;
  116.           ]]>
  117.         </body>
  118.       </method>
  119.     </implementation>
  120.   </binding>
  121. </bindings>
  122.